from django.shortcuts import render, redirect
from app01 import models
from app01.models import Department, UserInfo, PrettyNum
from app01.utils.form import UserModelForm, PrettyModelForm, PrettyEditModelForm
from app01.utils.pageination_amd_search import Pagination
# Create your views here.
def depart_list(request):
    """部门列表"""

    queryset = Department.objects.all()
    return render(request,
                  'depart_list.html',
                  {'queryset': queryset})
def depart_add(request):
    """部门添加"""
    if request.method == 'GET':
        return render(request, 'depart_add.html')
    dept = request.POST.get('title')
    Department.objects.create(title=dept)
    return redirect("/depart/list/")
def depart_del(request):
    """删除功能"""
    nid = request.GET.get('nid')
    Department.objects.filter(id=nid).delete()
    return redirect("/depart/list/")
def depart_edit(request, nid):
    """修改部门"""
    if request.method == 'GET':
        # 查询数据库对象
        row_object = Department.objects.filter(id=nid).first()
        return render(request,
                      'depart_edit.html',
                      {'row_object': row_object})
    Department.objects.filter(id=nid).update(title=request.POST.get('title'))
    return redirect("/depart/list/")